import urllib.request
import html2text as ht
import time
import json



with open('file/res.txt', 'w') as f:
    f.writelines('')

for line in open("file/ip.txt", "r"):
  url = 'https://ip.ws.126.net/ipquery?ip=' + line
  response = urllib.request.urlopen(url)
  str = response.read().decode('gbk')
  arr = str.split('var')[1].split('"')
  res = arr[1] + ' | ' + arr[3]
  print(res)
  with open('res.txt', 'a') as f:
    f.writelines(res)
    f.writelines('\r\n')
  time.sleep(1)


print('=====================查询完成======================')  



# while True:
#   response = urllib.request.urlopen()
#   str = response.read().decode('gbk')
#   time.sleep(1)
#   print(str)


# text_maker = ht.HTML2Text()

# text = text_maker.handle(str)
# print(text)

# with open('框架/常见问题.md', 'w', encoding='utf-8') as f:
  # f.write(text)